package com.jrx.anytxn.transaction;

import com.jrx.anytxn.feign.gateway.bean.ApiResponse;
import com.jrx.anytxn.feign.gateway.response.CouponResponse06;
import com.jrx.anytxn.feign.gateway.service.IOuterGatewayService;
import org.mockito.Mockito;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import static org.mockito.ArgumentMatchers.anyString;

@Order(Ordered.HIGHEST_PRECEDENCE)
@Component
class MockInitCommandLineRunner implements CommandLineRunner {

    @MockBean
    IOuterGatewayService iOuterGatewayService;

    @Override
    public void run(String... args) throws Exception {
        // mockito
        CouponResponse06 mockRes06 = new CouponResponse06();
        mockRes06.setCardNo("123456789");
        mockRes06.setCardPassword("987654321");
        mockRes06.setOrderState("2");
        mockRes06.setSceneOrderId("123456789");

        ApiResponse<CouponResponse06> mockErrRes = new ApiResponse<>(500, "权益不存在", null, null, null);
        ApiResponse<CouponResponse06> mockNormalRes = new ApiResponse<>(1000, "成功", System.currentTimeMillis(), System.currentTimeMillis(), mockRes06);

//        // 处理中
//        mockNormalRes.getData().setOrderState("0");
//        mockNormalRes.getData().getCards().get(0).setCardNo("");
//        mockNormalRes.getData().getCards().get(0).setCardPassword("");
//
        // 处理成功
        mockNormalRes.getData().setOrderState("2");

        // 处理失败
//        mockNormalRes.getData().setOrderState("3");
//        mockNormalRes.getData().getCards().get(0).setCardNo("");
//        mockNormalRes.getData().getCards().get(0).setCardPassword("");


        Mockito.when(iOuterGatewayService.cardCouponDetail(anyString())).thenReturn(mockNormalRes);
    }
}
